import os

import yaml


class FileTool:
    @classmethod
    def get_project_dir(cls):
        '''
        :param filename: 文件名
        :return: 返回项目根节点路径
        '''
        # 获取项目根节点路径
        _path = os.path.dirname(os.path.dirname(os.path.abspath(__name__)))
        return _path

    @classmethod
    def read_yaml(cls,filename):
        project_path = FileTool.get_project_dir()
        # 项目根节点路径+文件存放的目录名+文件名+后缀拼接
        file_path = os.sep.join([project_path,"datas",filename+".yaml"])
        # 打开文件
        with open(file_path,encoding='utf-8') as f:
            yaml_cotent = yaml.safe_load(f)
            return yaml_cotent


if __name__ == '__main__':
    print(FileTool.read_yaml("secrets"))